﻿using System;
using System.Windows.Media;
using System.Windows.Navigation;
using Caliburn.Micro;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Wulong.Phone.Dianping.i18n;

namespace Wulong.Phone.Dianping.Views
{
    public partial class MainView
    {
        public MainView()
        {
            InitializeComponent();
            LoadAppBar();
            HubTileService.FreezeGroup("groupon");
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            NavigationService.RemoveBackEntry(); 
        }

        private void LoadAppBar()
        {
            // Set the page's ApplicationBar to a new instance of ApplicationBar
            ApplicationBar = new ApplicationBar();

            var searchButton = new AppBarButton
            {
                IconUri = new Uri("/Images/Appbar.Search.png", UriKind.Relative),
                Text = AppResources.Btn_Search,
                Message = "Search"
            };

            ApplicationBar.Buttons.Add(searchButton);

            var aboutMenuItem = new AppBarMenuItem
                                    {
                                        Text = AppResources.App_About,
                                        Message = "GoToAboutPage"
                                    };
            ApplicationBar.MenuItems.Add(aboutMenuItem);
            ApplicationBar.IsVisible = true;
            ApplicationBar.Mode = ApplicationBarMode.Default;
            ApplicationBar.Opacity = 0.85;
            ApplicationBar.BackgroundColor = Colors.Black;
        }

        private void Panorama_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            ApplicationBar.IsVisible = pano.SelectedIndex != 2;
            if(pano.SelectedIndex==1)
                HubTileService.UnfreezeGroup("groupon");
            else
                HubTileService.FreezeGroup("groupon");
        }
    }
}